package com.jade.linkong.controller;

import java.util.List;

import com.jade.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jade.common.annotation.Log;
import com.jade.common.enums.BusinessType;
import com.jade.linkong.domain.LkInstructions;
import com.jade.linkong.service.ILkInstructionsService;
import com.jade.common.core.controller.BaseController;
import com.jade.common.core.domain.AjaxResult;
import com.jade.common.utils.poi.ExcelUtil;
import com.jade.common.core.page.TableDataInfo;

/**
 * 批示Controller
 * 
 * @author jade
 * @date 2020-08-13
 */
@Controller
@RequestMapping("/linkong/instructions")
public class LkInstructionsController extends BaseController
{
    private String prefix = "linkong/instructions";

    @Autowired
    private ILkInstructionsService lkInstructionsService;

    @RequiresPermissions("linkong:instructions:view")
    @GetMapping()
    public String instructions()
    {
        return prefix + "/instructions";
    }

    /**
     * 查询批示列表
     */
    @RequiresPermissions("linkong:instructions:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LkInstructions lkInstructions)
    {
        startPage();
        List<LkInstructions> list = lkInstructionsService.selectLkInstructionsList(lkInstructions);
        return getDataTable(list);
    }

    @RequiresPermissions("linkong:instructions:list")
    @PostMapping("/list/{proId}")
    @ResponseBody
    public TableDataInfo listByProId(@PathVariable("proId") String  proId)
    {
        startPage();
        LkInstructions lkInstructionsll = new LkInstructions();
        lkInstructionsll.setLkProjectId(proId);
        lkInstructionsll.setDelFlag("0");
        List<LkInstructions> list = lkInstructionsService.selectLkInstructionsList(lkInstructionsll);
        return getDataTable(list);
    }

    /**
     * 导出批示列表
     */
    @RequiresPermissions("linkong:instructions:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LkInstructions lkInstructions)
    {
        List<LkInstructions> list = lkInstructionsService.selectLkInstructionsList(lkInstructions);
        ExcelUtil<LkInstructions> util = new ExcelUtil<LkInstructions>(LkInstructions.class);
        return util.exportExcel(list, "instructions");
    }

    /**
     * 查看新增批示
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    @GetMapping("/add/{proId}/{proName}")
    public String add(@PathVariable("proId") String  proId, @PathVariable("proName") String  proName, ModelMap modelMap)
    {
        modelMap.put("proId", proId);
        modelMap.put("proName", proName);
        return prefix + "/addInstructions";
    }

    @GetMapping("/view/{proId}")
    public String view(@PathVariable("proId") String  proId, ModelMap modelMap)
    {
        modelMap.put("proId", proId);
        return prefix + "/viewInstructions";
    }

    /**
     * 新增保存批示
     */
    @RequiresPermissions("linkong:instructions:add")
    @Log(title = "批示", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LkInstructions lkInstructions)
    {
        lkInstructions.setInstructionsUserId(ShiroUtils.getSysUser().getUserId());
        lkInstructions.setInstructionsUserName(ShiroUtils.getSysUser().getUserName());
        return toAjax(lkInstructionsService.insertLkInstructions(lkInstructions));
    }

    /**
     * 修改批示
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LkInstructions lkInstructions = lkInstructionsService.selectLkInstructionsById(id);
        mmap.put("lkInstructions", lkInstructions);
        return prefix + "/edit";
    }

    /**
     * 修改保存批示
     */
    @RequiresPermissions("linkong:instructions:edit")
    @Log(title = "批示", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LkInstructions lkInstructions)
    {
        return toAjax(lkInstructionsService.updateLkInstructions(lkInstructions));
    }

    /**
     * 删除批示
     */
    @RequiresPermissions("linkong:instructions:remove")
    @Log(title = "批示", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lkInstructionsService.deleteLkInstructionsByIds(ids));
    }
}
